package com.zan.pattern.prototype.test1;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

/**
 * @Author Zan
 * @Create 2024/4/25 10:36
 * @Description : TODO(请用一句话描述该类的功能)
 * @ClassName: CitationTest
 */
public class CitationTest {
    public static void main(String[] args) throws Exception {
        // 1.创建原型对象
        Citation citation = new Citation();
        // 创建张三学生对象
        Student student = new Student();
        student.setName("张三");
        citation.setStudent(student);

        citation.show();

        // 2.创建输出流对象
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("F:/202308202019036594.txt"));
        // 写对象
        oos.writeObject(citation);
        // 释放资源
        oos.close();

        // 创建输入流对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("F:/202308202019036594.txt"));
        // 读取对象
        Citation citation1 = (Citation) ois.readObject();
        // 释放资源
        ois.close();

        citation1.getStudent().setName("李四");
        citation1.show();
    }
}
